﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using DocumentFormat.OpenXml.Packaging;
using DocumentFormat.OpenXml;
using DocumentFormat.OpenXml.Wordprocessing;

namespace component
{
    public partial class DocxBuilderComponent
    {
        public static List<OpenXmlElement> returnDeveloperHowToElements(XmlNode doc)
        {
            List<OpenXmlElement> developerHowToElements = new List<OpenXmlElement>();

            foreach (XmlNode node in doc)
            {
                switch (node.Name)
                {
                    case "title":
                        {
                            if (node.HasChildNodes)
                            {
                                Paragraph p = new Paragraph();
                                ParagraphProperties pPr = new ParagraphProperties();
                                ParagraphStyleId pStyleId = new ParagraphStyleId() { Val = "Title" };
                                pPr.Append(pStyleId);
                                p.Append(pPr);
                                List<OpenXmlElement> listPara = elementPara(node);
                                foreach (OpenXmlElement r in listPara)
                                    p.Append(r);
                                developerHowToElements.Add(p);
                            }
                        }
                        break;
                    case "summary":
                        {
                            if (node.HasChildNodes)
                            {
                                foreach (OpenXmlElement element in blockElement(node))
                                    developerHowToElements.Add(element);
                            }
                            break;
                        }
                    case "introduction":
                        {
                            if (node.HasChildNodes)
                            {
                                foreach (OpenXmlElement element in blockElement(node))
                                    developerHowToElements.Add(element);
                            }
                        }
                        break;
                    case "procedure":
                        {
                            if (node.HasChildNodes)
                            {
                                foreach (XmlNode element in node)
                                {
                                    if (element.NodeType == XmlNodeType.Element)
                                    {
                                        switch (element.Name)
                                        {
                                            case "title":
                                                {
                                                    //добавляем заглавие
                                                    if (element.HasChildNodes)
                                                    {
                                                        Paragraph p = new Paragraph();
                                                        ParagraphProperties pPr = new ParagraphProperties();
                                                        ParagraphStyleId pStyleId = new ParagraphStyleId() { Val = "Title" };
                                                        pPr.Append(pStyleId);
                                                        p.Append(pPr);
                                                        List<OpenXmlElement> listPara = elementPara(node);
                                                        foreach (OpenXmlElement r in listPara)
                                                            p.Append(r);
                                                        developerHowToElements.Add(p);
                                                    }
                                                }
                                                break;
                                            case "steps":
                                                {
                                                    if (element.HasChildNodes)
                                                    {
                                                        int numberStep = 1;
                                                        foreach (XmlNode step in element)
                                                        {
                                                            if (step.NodeType == XmlNodeType.Element && step.Name == "step")
                                                            {
                                                                Paragraph p = new Paragraph();
                                                                ParagraphProperties pPr = new ParagraphProperties();
                                                                ParagraphStyleId pStyleId = new ParagraphStyleId() { Val = "Title" };
                                                                pPr.Append(pStyleId);
                                                                p.Append(pPr);
                                                                p.Append(new Run(new Text("Шаг №" + numberStep)));
                                                                developerHowToElements.Add(p);

                                                                foreach (OpenXmlElement el in blockElement(step))
                                                                    developerHowToElements.Add(el);

                                                                numberStep++;
                                                            }
                                                        }
                                                    }
                                                }
                                                break;
                                        }
                                    }
                                }
                            }
                        }
                        break;
                    case "codeExample":
                        break;
                    case "buildInstructions":
                        break;
                    case "robustProgramming":
                        break;
                    case "security":
                        break;
                    case "relatedTopics":
                        break;
                }
            }

            return developerHowToElements;
        }
    }
}
